import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.odps.udf.UDF;

public class SpliderAliThsinfossInfo extends UDF {

	public String evaluate(String str) {
		if (StringUtils.isNotBlank(str)) {
			JSONObject obg = new JSONObject();
			String[] split = str.split("\\\\n");
			obg.put("size", split.length);
			for (int i = 0; i < split.length; i++) {
				if (split[i].contains("用途") || split[i].contains("适用范围")) {
					obg.put("main_use", split[i]);
				}
				if (split[i].contains("建议添加量") || split[i].contains("推荐使用量")) {
					obg.put("add_weight", split[i]);
				}
				if (split[i].contains("作用")) {
					obg.put("function", split[i]);
				}
				if (split[i].contains("描述") || split[i].contains("性能及应用") || split[i].contains("说明")) {
					obg.put("desc", split[i]);
				}
				if (split[i].contains("有效成分") || split[i].contains("化学成分") || split[i].contains("主要成分")) {
					obg.put("inci_name", split[i]);
				}
				if (split[i].contains("外观") || split[i].contains("性状")) {
					obg.put("shape", split[i]);
				}
				if (split[i].contains("色泽") || split[i].contains("颜色")) {
					obg.put("color", split[i]);
				}
				if (split[i].contains("气味") || split[i].contains("香气")) {
					obg.put("smell", split[i]);
				}

			}
			return JSON.toJSONString(obg);
		}
		return null;
	}

}
